<?php


session_start();
include_once('inc/config.inc.php');

/* ====================================================
 * Defaultní nastavení
 * ==================================================== */
$config["app"]["jmeno"] = 'Archeolo';

if(empty($show["GoogleMap"])) 	$show["GoogleMap"] = false;
if(empty($show["NoTop"])) 		$show["NoTop"] = false;
if(empty($show["HeadOnly"])) 	$show["HeadOnly"] = false;



/* =================================
 * Databáze
 * ================================= */
include_once('plugins/adodb/adodb.inc.php');
//Pripojeni k db
$db = &ADONewConnection($config["db"]["type"]);
$db->PConnect($config["db"]["host"], $config["db"]["usrName"], $config["db"]["usrPass"], $config["db"]["database"]);
$db->charSet = 'UTF-8';
$db->debug = $config["debug"];

$db->Execute("SET character_set_results=UTF8");
$db->Execute("SET character_set_connection=UTF8");
$db->Execute("SET character_set_client=UTF8");

/* =================================
 * Emaily
 * ================================= */
$config["MailSys"]["from"] 		= "From: \"".$config["app"]["jmeno"]."\" <".$config["email"]["from"].">\n";
$config["MailSys"]["xsender"] 	= "X-Sender: <".$config["email"]["from"].">\n";
$config["MailSys"]["return"] 	= "Return-Path: <".$config["email"]["return"].">\n";
$config["MailSys"]["mailer"] 	= "X-Mailer: ".$config["app"]["jmeno"]." PHP\n";
$config["MailSys"]["msgid"]	 	= "Message-ID: <".date("YmdHis")."is-".strtolower($config["app"]["jmeno"])."@".$_SERVER['SERVER_NAME'].">\n"; //identifikator
$config["MailSys"]["charset"] 	= "Content-type: text/html;charset=UTF-8\n";


/* =================================
 * Potřebné soubory
 * ================================= */
require_once('inc/function.inc.php');

$vyloucenLogin = array("sendPass","error");
if(!in_array($_GET["noAuth"],$vyloucenLogin)) {
    
	require_once('inc/auth.inc.php');
}
/*
if($show["NoTop"] == false) {
	include_once('inc/head.inc.php');
	echo TopContainer();
}
*/

if($show["NoTop"] == false AND $show["HeadOnly"] == false) {
	include_once('inc/head.inc.php');
	echo TopContainer();
}elseif($show["HeadOnly"] == true) {
	include_once('inc/head.inc.php');
}


/* =================================
 * Definice nastavení z configu
 * ================================= */

//strankovani
global $config;
unset($config["pocetZaznamuNaStranku"]);
foreach($config["pocetZaznamuNaStrankuSet"] as $key => $row) {
    $config["pocetZaznamuNaStranku"][] = array("value"=> $row,"textNazev"=> $row);
}

/* =================================
 * Nahrání globalniho nastavení
 * ================================= */
function loadSet($vlastnostNastaveni = "") {
	global $db;
	
	if(!empty($vlastnostNastaveni)) {
		$where = " WHERE vlastnost = '".$vlastnostNastaveni."'";
	}
	
	
	$query = "
				SELECT
							vlastnost,
							hodnota
				FROM 
							core_nastaveni
				".$where."
				";
	if(!empty($vlastnostNastaveni)) {
		$row = $db->GetRow($query);
		return $row["hodnota"];
	} else {
		//Pokud je podminka pro vraceni jedne vlastnosti prazdna, nahrajeme vsechny vlastnosti do pole.
		//urceno pro prvotni inicializaci
		unset($config["SET"]);
		$result = $db->Execute($query);
		foreach($result as $key => $row) {
			$config["SET"][$row["vlastnost"]] = $row["hodnota"];
		}
	}
}

/* =================================
 * Odhlaseni uzivatele
 * ================================= */
 if($_GET["logout"] == true) {
    Logout();
 }

?>